package com.galo.service.rabbitmq;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.galo.service.common.HttpAPIService;
import com.galo.service.common.HttpResult;

/**
 * @Auther: lxlin
 * @Date: 2018/10/24 15:03
 * @Description:
 */
@Component
@RabbitListener(queues = "topic.rep")
public class RepTopicReceiver {

    @Resource
    private HttpAPIService httpAPIService;
    private static final Logger logger =LoggerFactory.getLogger(RepTopicReceiver.class);
    public static final String callbackurl = "http://api.galo.2jz.info/callback.txt";

    @RabbitHandler
    public void process(String message) throws Exception {

        logger.info("Rep Receiver  : " + message);

        JSONObject data = JSONObject.parseObject(message);
        Map<String, Object> map=new LinkedHashMap<>();
        map.put("code", 200);
        map.put("message", "返回成功");
        map.put("data", data);
        HttpResult result=httpAPIService.doPost(callbackurl, map);

        logger.info("回调返回结果:" + result.getBody());
    }
}
